package com.order.manager.controller;

import com.order.manager.Model.Coffee;
import com.order.manager.service.CoffeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/coffee")
public class CoffeeController {

    @Autowired
    private CoffeeService coffeeService;

    // 新增咖啡物料信息
    @PostMapping("/add")
    public boolean addCoffee(@RequestBody Coffee coffee) {
        return coffeeService.save(coffee);
    }

    // 根据ID删除咖啡物料信息
    @DeleteMapping("/delete/{matId}")
    public boolean deleteCoffee(@PathVariable Integer matId) {
        return coffeeService.removeById(matId);
    }

    // 修改咖啡物料信息
    @PutMapping("/update/{matId}")
    public boolean updateCoffee(@PathVariable Integer matId, @RequestBody Coffee coffee) {
        coffee.setMatId(matId);
        return coffeeService.updateById(coffee);
    }

    // 根据ID查询咖啡物料信息
    @GetMapping("/get/{matId}")
    public Coffee getCoffee(@PathVariable Integer matId) {
        return coffeeService.getById(matId);
    }

    // 查询所有咖啡物料信息列表
    @GetMapping("/list")
    public List<Coffee> listCoffees() {
        return coffeeService.list();
    }
}
